package com.quartz_test2;

import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import org.quartz.impl.StdSchedulerFactory;

import static org.quartz.JobBuilder.newJob;
import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
import static org.quartz.TriggerBuilder.newTrigger;

/**
 * Hello world!
 */
public class App {

    private static final int SECONDS = 5;  //多少秒执行一次这个傻逼任务

    public static void main(String[] args) throws SchedulerException {

        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();

        //配置任务的描述等
        JobDetail job = newJob(MyJob.class)
                .withIdentity("job1", "group1")
                .withDescription("这玩意儿是干嘛的")
                .build();

        //配置任务的执行规律等等
        Trigger trigger = newTrigger()
                .withIdentity("trigger1", "group1")
                .startNow()
                .withSchedule(simpleSchedule()
                        .withIntervalInSeconds(SECONDS)
                        .repeatForever())
                .build();

        //组装好任务
        scheduler.scheduleJob(job, trigger);

        System.out.println("开始启动傻逼模式");

        //启动
        scheduler.start();
    }


}
